<?php
$listeUsers = array();
$message ="";
/*
 * a lire dans un fichier on sera plus large
 */
array_push($listeUsers, array("username" => "najib", "password" => "pass"));
array_push($listeUsers, array("username" => "antoine", "password" => "pass"));
array_push($listeUsers, array("username" => "yohann", "password" => "pass"));
array_push($listeUsers, array("username" => "kevin", "password" => "pass"));
if (isset($_POST) && !empty($_POST)) {
    foreach ($listeUsers as $d) {
        if(($d["username"] === $_POST["username"])AND($d["password"] === $_POST["password"])) {
            header('Status: 301 Moved Permanently', false, 301);
            header('Location: ./index.html?username=' . $_POST["username"]);
            exit();
        }
    }
       $message ="utilisateur non enregistré :";
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link href="Content/jquery.mobile.theme-1.2.0.min.css" rel="stylesheet" />
        <link href="Content/jquery.mobile-1.2.0.min.css" rel="stylesheet" />
    </head>
    <body>

        <div data-role="page" id="Login">

            <div data-role="header">
                <h1>Fotos y recuerdos</h1>
            </div>


            <div data-role="content">
                <form id="loginForm" data-ajax="false" action="login.php" method="post">
                    <input type="hidden" name="redirect" value="index.html" /> 

                    <div data-role="fieldcontain">
                        <?php
                        if(!empty($message)){
                            echo "<h5>".$message."</h5><br/>";}
                        ?>
                        <label for="username">Username:</label>
                        <input type="text" id="username" name="username" />
                    </div>
                    <div data-role="fieldcontain">
                        <label for="password">Password:</label>
                        <input type="password" name="password" id="password"/>
                    </div>
                    <div class="ui-body ui-body-b">
                        <fieldset class="ui-grid-a">
                            <div class="ui-block-b">
                                <input id="submit" name="submit" type="submit" value="se connecter" data-theme="a"/>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>

            <div data-role="footer" data-position="fixed">
                <h4>&copy; IHM project</h4>
            </div>

        </div>

        <script src="scripts/jquery-1.8.3.js"></script>
        <script src="scripts/jquery.mobile-1.2.0.js"></script>
        <script src="scripts/jquery.form.js"></script>
        <!--<script src="scripts/jquery.mobile-1.2.0.min.js"></script>-->

    </body>
</html>
